<template>
  <h1>用户添加</h1>
  用户名:<input type="text" v-model="userName"><br/>
  密码:<input type="text" v-model="password"><br/>

  <button @click="save">保存</button>

  <router-link to="/users/list">返回列表</router-link><br/>
</template>

<script setup>
import {postData} from "../../js/remote";
import { useRouter } from "vue-router";
const router = useRouter();

const userName = $ref('')
const password = $ref('')
const loginToken = localStorage.getItem('token')

function save(){
  postData('/user/save?token='+loginToken,{userName:userName,password:password}).then( (res)=>{
    console.log(res)
    router.push('/users/list')
  } )
}

</script>

<style scoped>

</style>